#!/usr/bin/env bash

if [[ "$1" =~ ^[0-9]+$ ]]; then
  times=$1
else
  times=10
fi

function dl {
  ansible-playbook -b play-all.yml -t download
}

for (( i = 0; i <= $times; i++ )); do
  dl
  if [[ $? == 0 ]]; then
    exit 0
  else
    echo ""
    echo "============================="
    echo "= The #$i retry ="
    echo "============================="
    echo ""
  fi
done
